<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class FDealer extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('dealer_model');
		$this->load->model('car_model');
	}

	function index()
	{
		$page["_contents"] = "frontend/dealer/v_dealer";
		$data["query_prov"] = $this->dealer_model->getProvince();
		$this->template->load("frontend/template/main_template",$page,$data);
	}

	function load_list()
	{
		$arr['data'] = array();
		$query = $this->dealer_model->getAll();
		
		foreach($query->result() as $row)
		{
			$data = array();
			array_push($data,$row->dealer_name);
			array_push($data,$row->nama_kab);
			array_push($data,$row->address);

			array_push($arr['data'],$data);
		}		
		//echo $car_id;
		echo json_encode($arr);
	}

	function load_list_prov()
	{
		$arr['data'] = array();
		$id_prov = $this->uri->segment(3);
		$query = $this->dealer_model->getByProvinsi($id_prov);
		
		foreach($query->result() as $row)
		{
			$data = array();
			array_push($data,$row->dealer_name);
			array_push($data,$row->nama_kab);
			array_push($data,$row->address);

			array_push($arr['data'],$data);
		}		
		//echo $car_id;
		echo json_encode($arr);
	}

	function load_list_kab()
	{
		$arr['data'] = array();
		$id_kab = $this->uri->segment(3);
		$query = $this->dealer_model->getByKabupaten($id_kab);
		
		foreach($query->result() as $row)
		{
			$data = array();
			array_push($data,$row->dealer_name);
			array_push($data,$row->nama_kab);
			array_push($data,$row->address);

			array_push($arr['data'],$data);
		}		
		//echo $car_id;
		echo json_encode($arr);
	}

	function load_kabupaten()
	{
		$id_prov = $this->input->post('id_prov');

		$q = $this->dealer_model->getKabupaten($id_prov);
		echo '<option value="">- Select City -</option>';
		foreach($q->result() as $row)
		{
			echo "<option value='". $row->id ."'>". $row->nama ."</option>";
		}
		exit;
	}

}

/* End of file FDealer.php */
/* Location: ./application/controllers/FDealer.php */